<%@page import="net.vinote.smart.platform.service.awe.layout.easyui.Tree"%>
<%@page import="org.json.JSONObject"%>
<%@page import="org.json.JSONArray"%>
<%@page import="net.vinote.smart.platform.service.awe.layout.FullLayout"%>
<%@page import="net.vinote.smart.platform.service.bean.LayoutItem"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!--树图布局-->
<%@include file="/comm/begin.jsp"%>
<%
	Tree tree=new Tree();
	String pageID = request.getParameter("LayoutID");
	List<LayoutItem> layoutItem = SRE.getLayoutItems(pageID);
	tree.setId(pageID);
	
	//若未指定节点,默认选中第一个
	int nodeindex=(int)(Math.random()*100);//随机生成首个节点号
	String selected=null;
	if(selected==null){
		selected=pageID+nodeindex;
	}
	JSONArray jsonArray=new JSONArray();
	for(LayoutItem item:layoutItem){
		JSONObject jsonBO=new JSONObject();
		JSONObject attrBo=new JSONObject();
		jsonBO.put("id", pageID+nodeindex++);
		jsonBO.put("text", item.getTitle());
		attrBo.put("url", item.getPageUrl());
		jsonBO.put("attributes", attrBo);
		jsonArray.put(jsonBO);
	}
	tree.setAttribute("lines", "true");
	tree.setData(jsonArray.toString());
	
	FullLayout layout = new FullLayout(FullLayout.WEST);
	layout.setId(tree.getId());
	layout.setWestWidth("200px");
	layout.setWestHtml("<ul id='"+pageID+"'></ul> ");
%>
<%=layout.getHtml() %>
<script>
//"use strict"
$(function() {
	$('#<%=layout.getId()%>').layout();
	<%=tree.getHtml()%>
	$('#<%=tree.getId()%>').tree(
		{
			onSelect: function(node) {
				<!--仅处理叶节点的双击事件-->
				if($(this).tree('isLeaf',node.target)){
					AWE.OpenLayout('#<%=layout.getId()%>','center',node.attributes.url,"<%=request.getQueryString()%>");
				}
			},
		});
	$('#<%=tree.getId()%>').tree('select', $('#<%=tree.getId()%>').tree('find', '<%=selected%>').target);
});
</script>
<%@include file="/comm/end.jsp"%>
